package menupopupplugin2.popup.actions;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;

public class ActionFormWizard extends Wizard {

	private AutomaticalOrManualPage automaticalOrManualPage;
	protected InputConnectionURLPage inputConnectionURLPage;
	protected InputTemplateFilePage inputTemplateFilePage;
	protected InputPackageNamePage inputPackageNamePage;
	protected PersistentLayerChoose persistentLayerChoosePage;
	private int indexPage;
	private String projectPath;

	public ActionFormWizard(String projectPath) {
		super();
		setNeedsProgressMonitor(true);

		this.projectPath = projectPath.substring(0, projectPath.lastIndexOf('/'));	}

	@Override
	public void addPages() {
		inputPackageNamePage = new InputPackageNamePage(projectPath);
		automaticalOrManualPage = new AutomaticalOrManualPage();
		inputTemplateFilePage = new InputTemplateFilePage();
		inputConnectionURLPage = new InputConnectionURLPage();
		persistentLayerChoosePage = new PersistentLayerChoose();

		addPage(inputPackageNamePage);
		addPage(automaticalOrManualPage);
		addPage(inputTemplateFilePage);
		addPage(persistentLayerChoosePage);
		addPage(inputConnectionURLPage);
	}

	@Override
	public boolean needsPreviousAndNextButtons() {
		return super.needsPreviousAndNextButtons();
	}

	@Override
	public boolean canFinish() {
		CustomWizardPage wizardPage = (CustomWizardPage) getContainer()
				.getCurrentPage();

		return wizardPage.isFinish();
	}

	@Override
	public boolean performFinish() {
		// Print the result to the console
		IWizardPage wizardPage = getContainer().getCurrentPage();

		if (wizardPage == automaticalOrManualPage)
			indexPage = 2;

		else if (wizardPage == inputConnectionURLPage) {
			indexPage = 6;
			inputConnectionURLPage.transitionFromTextControl();
		}

		return true;
	}

	public int getIndexPage() {
		return indexPage;
	}

	public void setIndexPage(int indexPage) {
		this.indexPage = indexPage;
	}
}